/**
 * Created by leman on 2017/7/12.
 */
'use strict';
salesCtrl.controller('generateBillCtrl', ['$rootScope', '$scope', '$http', '$location', '$stateParams' , function ($rootScope, $scope, $http, $location ,$stateParams) {
    //初始化第一页
    getPage($scope.p_current,$scope.p_pernum,function(){
        //alert("我是第一次加载");
    });
    function getPage(page,size,callback){
        // "xxx.html?status=0&page="+page+"&size="+size
        $http.post("payable/select-temp-list" ,{
            "versionNo":$stateParams.data
        }).success(function(res){
            $scope.data=res.data;
            // console.log(res.data.cost.versionNo)
            // $scope.p_current = page;
            $scope.p_all_page =Math.ceil($scope.count/$scope.p_pernum);
            callback();
        });
    }
    //单选按钮选中
    $scope.select= function(id){
        //alert(id);
    };

    //删除
    $scope.delBtn =function(){
        var value = this.x.id;
        if(!value){
            layer.msg('请选中删除项');
        }
        layer.confirm('是否确认删除？', {
            title: '提示'
            ,btn: ['确认','取消'] //按钮
        }, function(){
            // alert(arr)
            $http.post("payable/delete-payable-fee-detail-temp",{
                "id":value
            }).success(function(res){
                if(res.success){
                    //初始化第一页
                    getPage($scope.p_current,$scope.p_pernum,function(){
                    });
                    layer.msg('已成功删除', {
                        icon: 1
                    });
                }else{
                    getPage($scope.p_current,$scope.p_pernum,function(){
                    });
                    layer.msg('删除失败', {
                        icon: 1
                    });
                }
            });
        }, function(){
        });
    };
    //调整金额
    $scope.adjustBtn=function(){
        var id = this.x.id;
        var comment = this.x.comment == null ? "" : this.x.comment;
        var sysCost=this.x.sysCost;//订单金额
        var settleCost=this.x.settleCost;//结算金额
        var alterCost=this.x.alterCost==null ? 0 : this.x.alterCost;//调整金额
        layer.open({
            type: 2,
            title:'调整金额',
            area: ['400px', '380px'], //宽高
            content:"index/adjust?sysCost="+sysCost+"&settleCost="+settleCost+"&alterCost="+alterCost+"&comment="+comment,//传参数：订单价，调整金额，结算价
            btn:["确定","取消"],
            btnAlign: 'c', //按钮居中
            yes:function(index, layero){
                layer.close(index);
                //获取跳转页面的值：订单价，调整金额，结算价，调整页面
                var sysCost = $("#sysCost").val();
                var alterCost = $("#alterCost").val();
                var settleCost = $("#settleCost").val();
                var comment = $("#comment").val();
                $http.post("payable/update-temp-cost",{
                    "sysCost":sysCost,
                    "alterCost":alterCost,
                    "settleCost":settleCost,
                    "comment":comment,
                    "id":id
                }).success(function(res){
                    if(res.success) {
                        getPage($scope.p_current, $scope.p_pernum, function () {});
                        layer.msg('修改成功！');
                    }else{
                        layer.msg('修改失败！');
                    }
                });
            }
        });
    }



}]);


